package gui.customizer.panes.dhcp;

import java.util.HashMap;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;

public class GeneralOptions extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -407442428916814168L;
	private JTextField txtDefaultLeaseTime;
	private JTextField txtMaxLeaseTime;
	
	private HashMap<String, String> options;

	/**
	 * Create the panel.
	 */
	public GeneralOptions() {
		setLayout(new MigLayout("", "[grow]20[grow]", "[][]"));
		this.setBorder(BorderFactory.createTitledBorder("General Options"));
		
		JLabel lblDefaultLeaseTime = new JLabel("Default Lease Time");
		add(lblDefaultLeaseTime, "cell 0 0");
		
		JLabel lblMaxLeaseTime = new JLabel("Max Lease Time");
		add(lblMaxLeaseTime, "cell 1 0");
		
		txtDefaultLeaseTime = new JTextField();
		add(txtDefaultLeaseTime, "cell 0 1,growx");
		txtDefaultLeaseTime.setColumns(10);
		
		txtMaxLeaseTime = new JTextField();
		add(txtMaxLeaseTime, "cell 1 1,growx");
		txtMaxLeaseTime.setColumns(10);
		
	}
	
	public void setGeneralOptions(HashMap<String, String> options) {
		this.options = options;
		
		// Default Lease Time
		if (options.containsKey("default-lease-time")) {
			txtDefaultLeaseTime.setText(options.get("default-lease-time"));
		} else {
			txtDefaultLeaseTime.setText("");
		}
		
		// Max Lease Time
		if (options.containsKey("max-lease-time")) {
			txtMaxLeaseTime.setText(options.get("max-lease-time"));
		} else {
			txtMaxLeaseTime.setText("");
		}
	}
	
	public HashMap<String, String> getGeneralOptions() {
		// Default Lease Time
		if (!txtDefaultLeaseTime.getText().equals("")) {
			options.put("default-lease-time", txtDefaultLeaseTime.getText());
		}
		
		// Max Lease Time
		if (!txtDefaultLeaseTime.getText().equals("")) {
			options.put("max-lease-time", txtMaxLeaseTime.getText());
		}
		return options;
	}
}
